package zq.cn.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import utils.Globals;
import zq.cn.adapter.MyAdapter;

public class MainActivity extends AppCompatActivity {
    private GridView mainGrid;
    private List<Map<String, Object>> values;
    private MyAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Globals.init(this);

        mainGrid = (GridView) findViewById(R.id.main_grid);
        values = new ArrayList<>();
        for(int i=1;i<=30;i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("text", i);
            if(i<10) {
                map.put("passed", true);
            }else {
                map.put("passed", false);
            }
            values.add(map);
        }

        adapter = new MyAdapter(this, values);
        mainGrid.setAdapter(adapter);

        mainGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Map<String, Object> map = values.get(position);
                if((boolean) map.get("passed")) {
                    Toast.makeText(MainActivity.this,"已玩过", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(MainActivity.this,"未玩过", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
